package com.ubs.training.web.util;

import com.ubs.training.server.dao.model.Product;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Errors;

/**
 * Created with IntelliJ IDEA.
 * User: xubuntu
 * Date: 8/22/12
 * Time: 6:19 PM
 * To change this template use File | Settings | File Templates.
 */
public class ProductValidator {
    private Product product;
    private Errors res;

    public ProductValidator(Product product, Errors res) {
        this.product = product;
        this.res = res;

    }

    public void validate() {
        if(!StringUtils.hasLength(product.getName_product())) {
            res.rejectValue("name_product", "empty", "Name should not be empty");
        }
        if(product.getName_product()==null) {
            res.rejectValue("name_product", "toolong", "Name should be less than 30 characters");
        }
        if(StringUtils.hasLength(product.getName_product()) && product.getName_product().length()>30) {
            res.rejectValue("name_product", "toolong", "Name should be less than 30 characters");
        }
//        if(product.getStart_date()==null) {
//            res.rejectValue("start_date", "empty", "Date should not be empty");
//        }


    }
}
